# 1.导包
from sklearn.metrics import confusion_matrix
import pandas   as pd

# 2.准备数据
# 需求: 已知有十个样本,6个恶性,4个良性,AB模型预测结果绘制混淆矩阵
# 人工真是标签
y_test = ["恶性","恶性","恶性","恶性","恶性","恶性","良性","良性","良性","良性"] # 预测标签
print('人工真实标签:',y_test)
print("="*40)
#todo A模型预测并创建混淆矩阵
# A预测对了3个恶性,4个良性
y_pre_A = ["恶性","恶性","恶性","良性","良性","良性","良性","良性","良性","良性"] # 预测结果
cm_A = confusion_matrix(y_test, y_pre_A, labels=["恶性", "良性"])
print("A模型的混淆矩阵:",cm_A,end = '\n')

# TODO pandas友好展示混淆矩阵
cm_A_DF = pd.DataFrame(cm_A, index=["恶性(正例)", '良性(反例)'], columns=["恶性(正例)", "良性(反例)"])
print(cm_A_DF)
print("="*80)
# todo B模型预测并创建混淆矩阵
# B预测对了6个恶性 ,1个良性
y_pre_B = ['恶性','恶性','恶性','恶性','恶性','恶性','恶性','恶性','恶性','良性']

cm_B = confusion_matrix(y_test,y_pre_B,labels=['恶性','良性'])
print("B模型混淆矩阵:\n",cm_B,end = '\n')
# TODO 默认不加labels,也可以,如果labels变换了参数的位置,就会改变最终的混淆矩阵